<?php
$num=0;

function readCheckList($fileName){
	return array_map("trim", file("../files/completedInspections/$fileName"));
}

function saveCheckList(){

}

//parseTemplateLines : Array-of-string -> Array-of-groups
function parseCheckListLines($arrayOfStrings){
	$arrayOfGroups = array();  // declaration for the array of group headers
	$groupArray = array();  // array that will go inside arrayOfGroups
	$arrayOfQuestions = array();
	
	$isG = 0;  // starts at 0 to account for the initial increment	
	
	foreach($arrayOfStrings as $element){
		//If first letter is 'G' and $isEnd is set to one then that means we have a new group.
		if(substr($element, 0, 1)=='G'){
			//is adding $groupArray to $arrayOfGroups
			if($isG){
				$groupArray[1] = $arrayOfQuestions;
				array_push($arrayOfGroups, $groupArray);
				$groupArray = Null;
				$isG = 0;
			}
			//adding group header to $groupArray at position 0.
			$lineSplit = explode(":", $element);
			$lineData = $lineSplit[1];
			$groupArray[0] = $lineData;
			$isG = 1;
		}
		//add question, answer, comment, or photo location to array
		else{
			$lineSplit = explode(":", $element);
			$lineData = $lineSplit[1];
			array_push($arrayOfData, $lineData);
		}
	}
	$groupArray[1] = $arrayOfQuestions;
	array_push($arrayOfGroups, $groupArray);
	$groupArray = Null;
	
	return $arrayOfGroups;
}

}

function loadCheckList($arrayOfGroups){
	foreach($arrayOfGroups as $groupArray){
		renderGroup($groupArray);
	}
}
function renderGroup($groupArray){
	echo "<div class=\"heading\">$groupArray[0]</div>";
	echo "<ol>";
	foreach($groupArray[1] as $question){
		renderQuestion($question);
	}
	echo "</ol>";
}

function renderQuestion($string){
	global $num;
	echo "<li> 
			<p> $string </p>
			<span>
				<input type=\"radio\" name=\"$num\" id=\"y$num\" value=\"y\"/><label for=\"y$num\">Yes</label>
				<input type=\"radio\" name=\"$num\" id=\"n$num\" value=\"n\"/><label for=\"n$num\">No</label>
				<input type=\"radio\" name=\"$num\" id=\"_$num\" value=\"N/A\"/><label for=\"_$num\">N/A</label>
			</span>
		</li>";
	$num++;
}

